package com.heba.fragment.scan;

import android.os.Build;
import android.os.Bundle;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.text.Html;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.heba.Cfg;
import com.heba.adapter.QuickAdapter;
import com.heba.bean.PhotoObject;
import com.heba.bean.diary.ItemDiaryCommentObject;
import com.heba.bean.diary.ItemDiaryDetailObject;
import com.heba.bean.diary.ItemDiaryImageObject;
import com.heba.bean.diary.ItemDiaryTagObject;
import com.heba.bean.product.ItemProductInfoObject;
import com.heba.bean.product.ProductStar;
import com.heba.config.CommonConfig;
import com.heba.event.MessageEvent;
import com.heba.fragment.BaseFragment;
import com.heba.fragment.LazyFragment;
import com.heba.greenmulu.R;
import com.heba.greenmulu.ZoomPhotoActivity;
import com.heba.greenmulu.businesslist.BusinessHomePageActivity;
import com.heba.greenmulu.businesslist.BusinessPersonActivity;
import com.heba.greenmulu.diary.ItemDiaryAddActivity;
import com.heba.greenmulu.diary.ItemDiaryCommentActivity;
import com.heba.greenmulu.diary.ItemDiaryLikeListActivity;
import com.heba.greenmulu.diary.ItemPersonHomePageActivity;
import com.heba.greenmulu.message.ItemMessageSendActivity;
import com.heba.greenmulu.user.UserDiaryListActivity;
import com.heba.helper.DateHelper;
import com.heba.helper.HttpClientHelper;
import com.heba.helper.JSONHttpHelper;
import com.heba.helper.MemberShipHelper;
import com.heba.popupwindow.DiaryCommentPopupWindow;
import com.heba.utils.CommonUtils;
import com.heba.utils.DensityUtils;
import com.heba.utils.GlideUtil;
import com.heba.view.FlowLayout;
import com.heba.view.MyRatingBarView;
import com.loopj.android.http.RequestParams;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * 產品評價頁面
 * Created by jason on 2020/1/15.
 */
public class ProductCommentFragment extends LazyFragment {

    private View view_background;
    private Button btn_comment_add;
    private SmartRefreshLayout refreshLayout;
    private RecyclerView recyclerView;
    private QuickAdapter recycleAdapter;

    private List<ItemDiaryDetailObject> diaryDetailObjectList;
    private ItemProductInfoObject infoObject;

    /**
     * 評論彈出框
     */
    private DiaryCommentPopupWindow commentPopupWindow;

    private String diaryID;
    private int type;
    private String feedbackID;
    private String toUserID;

    /**
     * 接收的数据
     */
    private String productID = "";
    private String barCode = "";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void lazyLoad() {
        getProductInfoData();
    }

    /**
     * 傳遞參數
     *
     * @param productID
     * @param barCode
     * @return
     */
    public static ProductCommentFragment newInstance(String productID, String barCode) {
        ProductCommentFragment fragment = new ProductCommentFragment();
        Bundle bundle = new Bundle();
        bundle.putString(CommonConfig.PRODUCT_ID, productID);
        bundle.putString(CommonConfig.BARCODE, barCode);
        fragment.setArguments(bundle);
        return fragment;
    }

    /**
     * 取出参数
     */
    private void parseArgument() {
        Bundle bundle = getArguments();
        productID = bundle.getString(CommonConfig.PRODUCT_ID, "");
        barCode = bundle.getString(CommonConfig.BARCODE, "");
    }

    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_scan_product_comment, container, false);
        EventBus.getDefault().register(this);
        parseArgument();
        initView(view);
        initPopupWindow();
        return view;
    }

    /**
     * initPopupWindow
     */
    private void initPopupWindow() {
        /**
         * 評論彈出框
         */
        commentPopupWindow = new DiaryCommentPopupWindow(getActivity(), ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        commentPopupWindow.setOnDiaryCommentListener(content -> {
            /**
             * 用户留言处理
             */
            progressDialog.show();
            new MemberShipHelper(new MemberShipHelper.MembershipListener() {
                @Override
                public void Success() {
                    /**
                     * 留言评论成功，更新数据
                     */
                    progressDialog.dismiss();
                    commentPopupWindow.setCommentHint(getResources().getString(R.string.diary_comment));
                    commentPopupWindow.setCommentText("");
                    refreshDiaryListData();
                }

                @Override
                public void Fail(String error) {
                    progressDialog.dismiss();
                }
            }).addFeedback(getActivity(), diaryID, type, content, toUserID, feedbackID);
        });
        commentPopupWindow.setOnDismissListener(() -> view_background.setVisibility(View.GONE));
    }

    /**
     * initView
     *
     * @param view
     */
    private void initView(View view) {
        view_background = view.findViewById(R.id.view_background);
        btn_comment_add = view.findViewById(R.id.btn_comment_add);
        refreshLayout = view.findViewById(R.id.refreshLayout);
        recyclerView = view.findViewById(R.id.recyclerView);

        diaryDetailObjectList = new ArrayList<>();

        recycleAdapter = new QuickAdapter<ItemDiaryDetailObject>(diaryDetailObjectList) {
            @Override
            public int getLayoutId(int viewType) {
                switch (viewType) {
                    case 0:
                        return R.layout.include_layout_scan_product_comment_header;
                    default:
                        return R.layout.recycle_item_scan_product_comment;
                }
            }

            @Override
            public void convert(VH holder, ItemDiaryDetailObject data, int position) {
                if (position == 0) {
                    /**
                     * 显示产品信息
                     */
                    if (infoObject != null) {
                        //显示产品信息
                        ImageView img_photo = holder.getView(R.id.img_photo);
                        GlideUtil.loadImageWithDefaultPlaceHolder(getActivity(), infoObject.getIcon(), img_photo);
                        holder.setText(R.id.txt_title, infoObject.getBrandName());
                        holder.setText(R.id.txt_content, infoObject.getProductName());
                        holder.setText(R.id.txt_serving_size, String.format(getResources().getString(R.string.per_serving_size), infoObject.
                                getPackageSize(), infoObject.getPackageUnit(), CommonUtils.subZeroAndDot(infoObject.getServingSize()), infoObject.getServingSizeUnit()));
                        //显示评分信息
                        ProductStar starObject = infoObject.getStars();
                        if (starObject != null) {
                            MyRatingBarView ratingBar = holder.getView(R.id.rb_rating);
                            holder.setText(R.id.tv_num, starObject.getScore() + "");
                            ratingBar.setStar(starObject.getScore());
                            int totalNum = starObject.getStar1() + starObject.getStar2() + starObject.getStar3() + starObject.getStar4() + starObject.getStar5();
                            showRatingPbView(holder.getView(R.id.view_star_five), getResources().getString(R.string.scan_product_star_five), starObject.getStar5(), totalNum);
                            showRatingPbView(holder.getView(R.id.view_star_four), getResources().getString(R.string.scan_product_star_four), starObject.getStar4(), totalNum);
                            showRatingPbView(holder.getView(R.id.view_star_three), getResources().getString(R.string.scan_product_star_three), starObject.getStar3(), totalNum);
                            showRatingPbView(holder.getView(R.id.view_star_two), getResources().getString(R.string.scan_product_star_two), starObject.getStar2(), totalNum);
                            showRatingPbView(holder.getView(R.id.view_star_one), getResources().getString(R.string.scan_product_star_one), starObject.getStar1(), totalNum);
                        }

                        /**
                         * 查看大图
                         */
                        img_photo.setOnClickListener(v -> {
                            List<PhotoObject> list = new ArrayList<>();
                            PhotoObject object = new PhotoObject();
                            object.setImageUrl(infoObject.getIcon());
                            list.add(object);
                            Bundle bundle = new Bundle();
                            bundle.putSerializable(CommonConfig.PHOTOLIST, (Serializable) list);
                            openActivityWithFadeInAnimation(ZoomPhotoActivity.class, bundle);
                        });
                    }
                } else {
                    /**
                     * 显示产品评论列表
                     */
                    ImageView iv_avatar = holder.getView(R.id.iv_avatar);
                    GlideUtil.loadImageWithPlaceHolderID(getActivity(), data.getIcon(), iv_avatar, R.drawable.icon_head_portrait);
                    holder.setText(R.id.tv_name, data.getAccount());
                    ((MyRatingBarView) holder.getView(R.id.rb_view)).setStar(data.getStar());
                    holder.setText(R.id.tv_time, DateHelper.transferDateString(getActivity(), data.getTimeCreated()));
                    holder.setText(R.id.tv_desc, CommonUtils.getDecodeText(data.getContent()));
                    TextView iv_lookNumber = holder.getView(R.id.iv_lookNumber);
                    holder.setText(R.id.tv_read_num, String.format(getResources().getString(R.string.scan_product_comment_views), data.getViews()));
                    iv_lookNumber.setText(String.format(getResources().getString(R.string.scan_product_comment_views), data.getViews()));
                    /**
                     * 跳转个人主页
                     */
                    iv_avatar.setOnClickListener(v -> {
                        Bundle bundle = new Bundle();
                        bundle.putString(CommonConfig.SEND_USER_ID, data.getUserID());
                        if (data.getAccountType() == 0){
                            openActivity(ItemPersonHomePageActivity.class, bundle);
                        }else{
                            openActivity(BusinessPersonActivity.class, bundle);
                        }
                    });

                    /**
                     * 添加評論圖片
                     */
                    FlowLayout fl_photo_view = holder.getView(R.id.fl_photo_view);
                    updateCommentImageView(fl_photo_view, data.getImageList());

                    /**
                     * 添加话题標籤
                     */
                    FlowLayout fl_tag_view = holder.getView(R.id.fl_tag_view);
                    updateTagFlowView(fl_tag_view, data.getTalkList());

                    /**
                     * 留言、收藏、传送view显示
                     */
//                    EditText et_comment = holder.getView(R.id.et_comment);
                    ImageView et_comment = holder.getView(R.id.et_comment_icon);
                    ImageView iv_like = holder.getView(R.id.iv_like);
                    ImageView iv_send = holder.getView(R.id.iv_send);
                    holder.setText(R.id.tv_like_num, data.getLikeCount() + "");
                    //設置edittex不允許編輯
//                    et_comment.setFocusable(false);
                    et_comment.setFocusableInTouchMode(false);
//                    et_comment.setHint(String.format(getContext().getResources().getString(R.string.diary_reply_hint), data.getAccount()));
                    iv_like.setSelected(data.getIsLiked() == 1);

                    /**
                     * 彈出評論框
                     */
                    et_comment.setOnClickListener(v -> {
                        diaryID = data.getDiaryID();
                        type = 0;
                        feedbackID = "";
                        toUserID = data.getUserID();
                        showCommentPopupView(v, type, feedbackID, toUserID, getResources().getString(R.string.diary_comment));
                    });


                    /**
                     * 點讚或取消點讚事件監聽
                     */
                    iv_like.setOnClickListener(v -> {
                        //不能自己點讚自己，跳轉點讚列表
                        if (Cfg.UserID.equals(data.getUserID())) {
                            Bundle bundle = new Bundle();
                            bundle.putString(CommonConfig.DIARY_ID,data.getDiaryID());
                            bundle.putInt(CommonConfig.LIKE_COUNT, data.getLikeCount());
                            openActivity(ItemDiaryLikeListActivity.class, bundle);
                            return;
                        }

                        new MemberShipHelper(new MemberShipHelper.MembershipListener() {
                            @Override
                            public void Success() {
                                if (data.getIsLiked() == 1) {
                                    data.setIsLiked(0);
                                    data.setLikeCount(data.getLikeCount() - 1);
                                    iv_like.setSelected(false);
                                } else {
                                    data.setIsLiked(1);
                                    data.setLikeCount(data.getLikeCount() + 1);
                                    iv_like.setSelected(true);
                                }
                                notifyItemChanged(position);
                            }

                            @Override
                            public void Fail(String error) {

                            }
                        }).diaryLike(getActivity(), data.getDiaryID(), data.getIsLiked());
                    });

                    /**
                     * 傳送日記專頁
                     */
                    iv_send.setOnClickListener(v -> {
                        Bundle bundle = new Bundle();
                        bundle.putInt(CommonConfig.TYPE, CommonConfig.TYPE_SEND_DIARY);
                        bundle.putString(CommonConfig.MESSAGE_ID, data.getDiaryID());
                        openActivity(ItemMessageSendActivity.class, bundle);
                    });

                    /**
                     * 显示日记评论数据
                     */
                    View view_comment = holder.getView(R.id.view_comment);
                    LinearLayout ll_comment_view = view_comment.findViewById(R.id.ll_comment_view);
                    updateCommentView(ll_comment_view, data.getDiaryID(), data.getFeedbackCount(), data.getFeedback());

                    /**
                     * 跳轉到日記详情页面
                     */
                    holder.itemView.setOnClickListener(v -> {
                        Bundle bundle = new Bundle();
                        bundle.putInt(CommonConfig.TYPE, 1);
                        bundle.putString(CommonConfig.DIARY_ID, data.getDiaryID());
                        openActivity(UserDiaryListActivity.class, bundle);
                    });

                }
            }

            @Override
            public int getItemViewType(int position) {
                switch (position) {
                    case 0:
                        return 0;
                    default:
                        return 1;
                }
            }
        };

        /**
         * 设置layoutManager布局
         */
        LinearLayoutManager layoutManager = new LinearLayoutManager(getActivity());
        //设置布局管理器
        recyclerView.setLayoutManager(layoutManager);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        //设置Adapter
        recyclerView.setAdapter(recycleAdapter);
        //设置动画执行时间为0  防止局部刷新时闪烁
        recyclerView.getItemAnimator().setChangeDuration(0);

        //设置是否监听滚动到底部是触发自动刷新
        refreshLayout.setEnableAutoLoadMore(false);
//        refreshLayout.setEnableRefresh(false);
//        refreshLayout.setEnableLoadMore(false);

        /**
         * 处理下拉刷新事件
         */
        refreshLayout.setOnRefreshListener(refreshLayout -> {
            refreshDiaryListData();
        });

        /**
         * 处理上拉加载事件
         */
        refreshLayout.setOnLoadMoreListener(refreshLayout -> {
            Page++;
            isRefreshFromTop = false;
            getProductCommentListData();
        });

        /**
         * 新增產品評價
         */
        btn_comment_add.setOnClickListener(v -> {
            if (infoObject == null)
                return;
            Bundle bundle = new Bundle();
            bundle.putInt(CommonConfig.TYPE, 0);
            bundle.putSerializable(CommonConfig.PRODUCT_OBJECT, infoObject);
            openActivity(ItemDiaryAddActivity.class, bundle);
        });
    }

    /**
     * 显示评分人數view
     *
     * @param view
     * @param starContent
     * @param starNum
     * @param totalNum
     */
    private void showRatingPbView(View view, String starContent, int starNum, int totalNum) {
        TextView tv_star = view.findViewById(R.id.tv_star);
        ProgressBar progressBar = view.findViewById(R.id.pb_view);
        TextView tv_views = view.findViewById(R.id.tv_views);
        tv_star.setText(starContent);
        progressBar.setMax(totalNum);
        progressBar.setProgress(starNum);
        tv_views.setText(starNum + "");
    }

    /**
     * 更新产品评论图片view
     */
    private void updateCommentImageView(FlowLayout flowLayout, List<ItemDiaryImageObject> imageObjectList) {
        flowLayout.removeAllViews();

        int photoWidth = (ScreenWidth - DensityUtils.dip2px(getContext(), (float) 35.5)) / 3;
        FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(photoWidth, photoWidth);
        params.rightMargin = DensityUtils.dip2px(getContext(), 5);
        params.bottomMargin = DensityUtils.dip2px(getContext(), 5);
        if (!imageObjectList.isEmpty()) {
            for (int i = 0; i < imageObjectList.size(); i++) {
                ItemDiaryImageObject imageObject = imageObjectList.get(i);
                View view = LayoutInflater.from(getContext()).inflate(R.layout.item_round_image_row, null);
                ImageView img_photo = view.findViewById(R.id.roundImage);
                ImageView iv_play = view.findViewById(R.id.iv_play);
                view.setLayoutParams(params);
                //判斷是否顯示播放視頻的按鈕
                iv_play.setVisibility(View.GONE);
                if (imageObjectList.get(i).getType() == 1) {
                    iv_play.setVisibility(View.VISIBLE);
                }
                GlideUtil.loadImageWithDefaultPlaceHolder(getActivity(), imageObject.getImageUrl(), img_photo);

                flowLayout.addView(view);
            }
        }
    }

    /**
     * 更新流式佈局
     *
     * @param flowLayout
     * @param tags
     */
    private void updateTagFlowView(FlowLayout flowLayout, List<ItemDiaryTagObject> tags) {
        flowLayout.removeAllViews();

        if (tags == null)
            return;

        /**
         * 添加佈局參數
         */
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, DensityUtils.dip2px(getActivity(), 20));
        params.rightMargin = DensityUtils.dip2px(getActivity(), 8);
        params.bottomMargin = DensityUtils.dip2px(getActivity(), 3);
        for (int i = 0; i < tags.size(); i++) {
            flowLayout.addView(updateFlowRowView(tags.get(i)), params);
        }
    }

    /**
     * 添加item佈局
     */
    private View updateFlowRowView(ItemDiaryTagObject object) {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.item_tag_flow_row, null);
        TextView tv_text = view.findViewById(R.id.tv_text);
        tv_text.setText(object.getContent());
        return view;
    }

    /**
     * 更新日记评论布局
     *
     * @param ll_comment_view
     * @param diaryID
     * @param commentCount
     * @param commentObjectList
     */
    private void updateCommentView(LinearLayout ll_comment_view, String diaryID, int commentCount, List<ItemDiaryCommentObject> commentObjectList) {
        ll_comment_view.removeAllViews();

        if (commentObjectList == null)
            return;

        /**
         * 添加評論item
         */
        for (int i = 0; i < commentObjectList.size(); i++) {
            ll_comment_view.addView(updateCommentRowView(diaryID, commentObjectList.get(i)));
        }

        /**
         * 添加更多評論的view
         */
        if (commentCount > commentObjectList.size()) {
            ll_comment_view.addView(updateMoreCommentRowView(diaryID, commentCount));
        }
    }

    /**
     * 添加评论item布局
     *
     * @return
     */
    private View updateCommentRowView(String diaryID, ItemDiaryCommentObject object) {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.item_diary_comment_row, null);
        TextView tv_comment = view.findViewById(R.id.tv_comment);
        String commentStr = "<strong>" + object.getAccount() + "&nbsp;&nbsp;" + "</strong>" + CommonUtils.getDecodeText(object.getMessage());
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            tv_comment.setText(Html.fromHtml(commentStr, Html.FROM_HTML_MODE_COMPACT));
        } else {
            tv_comment.setText(Html.fromHtml(commentStr));
        }
        /**
         * 查看更多評論
         */
        view.setOnClickListener(v -> {
            Bundle bundle = new Bundle();
            bundle.putString(CommonConfig.DIARY_ID, diaryID);
            openActivity(ItemDiaryCommentActivity.class, bundle);
        });
        return view;
    }

    /**
     * 添加更多評論的view
     *
     * @param diaryID
     * @param count
     * @return
     */
    private View updateMoreCommentRowView(String diaryID, int count) {
        View view = LayoutInflater.from(getActivity()).inflate(R.layout.item_diary_more_text_row, null);
        TextView tv_more_comment = view.findViewById(R.id.tv_more_comment);
        tv_more_comment.setText(String.format(getActivity().getResources().getString(R.string.diary_comment_more), count));
        /**
         * 查看更多評論
         */
        view.setOnClickListener(v -> {
            Bundle bundle = new Bundle();
            bundle.putString(CommonConfig.DIARY_ID, diaryID);
            openActivity(ItemDiaryCommentActivity.class, bundle);
        });
        return view;
    }

    /**
     * 显示评论弹出框
     *
     * @param view
     * @param type      判断是日记留言 还是回复用户留言
     * @param commentID 回复用户留言ID
     * @param toUserID  回复目标用户ID
     * @param hint      输入框提示
     */
    private void showCommentPopupView(View view, int type, String commentID, String toUserID, String hint) {
        this.type = type;
        this.feedbackID = commentID;
        this.toUserID = toUserID;
        view_background.setVisibility(View.VISIBLE);
        commentPopupWindow.setCommentHint(hint);
        commentPopupWindow.showSoftKeyBoard();
        commentPopupWindow.showAtLocation(view, Gravity.BOTTOM, 0, 0);
    }

    /**
     * 获取产品规格详细数据
     */
    private void getProductInfoData() {
        isRefreshFromTop = true;
        HttpClientHelper client = new HttpClientHelper();
        client.setUseLogin(true);
        RequestParams params = new RequestParams();
        params.put("Leng", Cfg.Leng);
        params.put("ProductID", productID);
        params.put("Barcode", barCode);
        client.get(Cfg.BaseUrl + "/Product/GetProductInfo", params,
                new JSONHttpHelper.JSONHttpResponseHandler(getActivity()) {

                    @Override
                    public void Success() {
                        // TODO Auto-generated method stub
                        super.Success();
                        try {
                            JSONObject jsonObject = new JSONObject(response.trim()).getJSONObject("Result");
                            infoObject = new Gson().fromJson(jsonObject.toString(), ItemProductInfoObject.class);
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

//                        /**
//                         * 相当于占位，用于显示顶部的产品信息
//                         */
//                        diaryDetailObjectList.clear();
//                        diaryDetailObjectList.add(new ItemDiaryDetailObject());

                        /**
                         * 獲取評論列表
                         */
                        if (null != infoObject) {
                            productID = infoObject.getProductID();
                            getProductCommentListData();
                        }

                    }

                    public void Failure() {
                        super.Failure();
                    }

                });
    }

    /**
     * 獲取評論列表數據
     */
    private void getProductCommentListData() {
        HttpClientHelper client = new HttpClientHelper();
        client.setUseLogin(true);
        RequestParams params = new RequestParams();
        params.put("Leng", Cfg.Leng);
        params.put("p", Page);
        params.put("pp", PerPage);
        params.put("ProductID", productID);
        params.put("Type", 0);
        client.get(Cfg.BaseUrl + "/Diary/DiaryListing", params,
                new JSONHttpHelper.JSONHttpResponseHandler(getActivity()) {

                    @Override
                    public void Success() {
                        // TODO Auto-generated method stub
                        super.Success();
                        closeRefreshView(refreshLayout);

                        /**
                         * 下拉刷新处理
                         */
                        if (isRefreshFromTop) {
                            isRefreshFromTop = false;
                            refreshLayout.setNoMoreData(false);
                            diaryDetailObjectList.clear();
                            //占位，用于显示头部
                            diaryDetailObjectList.add(new ItemDiaryDetailObject());
                        }

                        try {
                            JSONArray array = new JSONObject(response.trim()).getJSONArray("Result");
                            if (array.length() > 0) {
                                List<ItemDiaryDetailObject> diaryDetailObjects = new Gson().fromJson(array.toString(), new TypeToken<List<ItemDiaryDetailObject>>() {
                                }.getType());
                                diaryDetailObjectList.addAll(diaryDetailObjectList.size(), diaryDetailObjects);
                            } else {
                                //无数据
                                refreshLayout.finishLoadMoreWithNoMoreData();
                            }
                        } catch (JSONException e) {
                            e.printStackTrace();
                        }

                        //刷新数据
                        recycleAdapter.notifyDataSetChanged();
                    }

                    public void Failure() {
                        super.Failure();
                        closeRefreshView(refreshLayout);
                    }

                });
    }

    /**
     * 刷新評價數據
     */
    private void refreshDiaryListData() {
        Page = 1;
        isRefreshFromTop = true;
        getProductCommentListData();
    }

    /**
     * 接收EventBus
     *
     * @param event
     */
    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEvent(MessageEvent event) {
        /**
         * 更新列表數據
         */
        if (event.getEvent().equals(CommonConfig.EVENT_REFRESH_DIARY_LIST)) {
            refreshDiaryListData();
        }
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        //反註冊
        EventBus.getDefault().unregister(this);
    }

}
